package repository.implementation;

import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;

public class RegistrationRepository
{
	private final Queue<RecipeModel> data;
	private final ConcurrentHashMap<String, Boolean> map;

	public RegistrationRepository()
	{
		data = new LinkedBlockingQueue<RecipeModel>();
		map = new ConcurrentHashMap<String, Boolean>();
	}

	public void RegisterNewRecipe(RecipeModel r)
	{
		try
		{
			if (!map.containsKey(r.recipeName))
				map.put(r.recipeName, true);
			else
				return;
			((LinkedBlockingQueue<RecipeModel>) data).put(r);
		} catch (InterruptedException e)
		{
			e.printStackTrace();
		}
	}

	public RecipeModel UnregisterRecipe() throws InterruptedException
	{
		return (RecipeModel) ((LinkedBlockingQueue<RecipeModel>) data).take();
	}

	public boolean isEmpty()
	{
		return data.isEmpty();
	}
}
